package com.banana.manager.forest.service.impl.info;

import com.banana.manager.forest.dao.userandinfo.IPestDao;
import com.banana.manager.forest.entity.info.PestBean;
import com.banana.manager.forest.service.iinfo.IPestService;
import com.banana.manager.forest.util.PageInfoSize;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.annotation.Resource;

@Service
@Transactional
public class PestServiceImpl implements IPestService {

    @Resource
    private IPestDao pestDao;

    @Override
    public PestBean addPest(PestBean pestBean) {
        pestDao.insert(pestBean);
        return pestDao.selectById(pestBean.getPestId());
    }

    @Override
    public PestBean findOneById(Integer id) {
        return pestDao.selectById(id);
    }

    @Override
    public PageInfo<PestBean> findBlurByPage(Integer page, String pestName, String pestHost) {
        QueryWrapper<PestBean> queryWrapper = new QueryWrapper<>();
        queryWrapper.like("pest_name","%"+pestName+"%");
        queryWrapper.like("pest_host","%"+pestHost+"%");
        PageHelper.startPage(page, PageInfoSize.pageSize);
        return PageInfo.of(pestDao.selectList(queryWrapper));
    }
}
